<?php

/**
 * First basic plugin
 *
 * @version $Id$
 * @copyright 2010
 */

class Skeleton extends Plugin
{
	public $plugin_name = "Skeleton"; //name of plugin
	public $plugin_short_desc = "Just skeleton"; //short description of plugin
	public $plugin_long_desc = "Just longer skeleton"; //longer description - what does plugin do
	public $version = "1.0"; //version of plugin
	public $has_sidebar = true; //does this plugin have sidebar -> function generate_sidebar()
	public $has_footer = true; //does this plugin have footer -> function generate_footer()

	/**
	 * Constructor
	 */
	function __construct()
	{
		global $theme,$db;
		$theme->set_title('Skeleton plugin'); //set page <title>
		$this->db = $db;
	}

	/**
	 * Skeleton::generate_sidebar()
	 * Generate simple sidebar
	 * @return
	 */
	public function generate_sidebar()
	{
		global $theme;

		$out = '<ul>';
		$out .= '<li><a href="skeleton-hahaha">Hahaha :)</a></li>';
		$out .= '</ul>';

		$theme->assign('sidebar',$out);
	}

	/**
	 * Skeleton::generate_footer()
	 * Generate simple footer
	 * @return
	 */
	public function generate_footer()
	{
		global $theme;

		$theme->assign('footer','Hi, i am footer');
	}

	/**
	 * Skeleton::hahaha2()
	 * hahaha2 function, will be called on skeleton-hahaha in url -> check actions_skeleton.php
	 * @return
	 */
	public function hahaha2()
	{
		echo 'Hahaha! I am skeleton in your closet! F34r meh :)';

		$form = Form::load('frm');
		$form->render();
	}

	public function frm_handle($name)
	{
		global $core,$theme;

		$theme->render = false;
		$form = Form::load($name);
		$form->update();
		if(!$form->error)
		{
			if($form->db_insert) //we will insert data from form to db
			{
				$form->insert_to_db();
				if($form->error) $form->return_back();
			}

			$form->remove();
			$core->refresh_header('skeleton');
		}
		else
		{
			$form->return_back();
		}
	}

	/**
	 * Skeleton::start()
	 * Default function for plugin output, when there is nothing else to call
	 * @return
	 */
	public function start()
	{
		$form = new Form('frm');
		//$form->remove();
		$form->db_table('yaps_formtest');
		$form->use_default_handler('skeleton');
		$form->jquery_validation();
		$form->addText('jmeno','Jmeno')->mandatory()->dbcol('jmeno');
		$form->addText('prijmeni','Prijmeni')->mandatory()->dbcol('prijmeni');
		$form->addPassword('heslo','Heslo')->mandatory()->dbcol('heslo')->hash_this();
		$form->addPassword('heslo2','Heslo podruhe')->mandatory()->sameas('heslo');

		$form->render();
	}

	/**
	 * Skeleton::admin_settings()
	 * Administration settings of plugin, if you can`t administrate anything it`s good to place some example of usage here
	 * It will be printed in administration of Yaps!
	 * @return
	 */
	public function admin_settings()
	{
		echo $this->db->num_rows("SELECT * FROM yaps_blog WHERE id = ;",1);

		$this->db->query("SELECT * FROM yaps_config");
		print_r($this->db->get_row());
		echo 'This is SKELETON!';
	}
}


?>